package com.hksj.wlw.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hksj.common.core.model.Rest;
import com.hksj.wlw.query.WaterLeakDeviceQuery;
import com.hksj.wlw.query.WaterLeakHistoryQuery;
import com.hksj.wlw.service.WaterLeakDeviceService;
import com.hksj.wlw.vo.WaterLeakCountVO;
import com.hksj.wlw.vo.WaterLeakDeviceHistoryVO;
import com.hksj.wlw.vo.WaterLeakDeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "无线漏水-设备管理")
@RestController
@RequestMapping("/api/wlw/waterLeakDevice")
public class WaterLeakDeviceController {

    @Autowired
    private WaterLeakDeviceService waterLeakDeviceService;

    @PostMapping("/queryWaterLeakDeviceByPage")
    @ApiOperation(value = "分页查询漏水设备信息",response = WaterLeakDeviceVO.class)
    public Rest<IPage<WaterLeakDeviceVO>> deviceOverView(@RequestBody WaterLeakDeviceQuery query){
        return Rest.ok(waterLeakDeviceService.queryWaterLeakDeviceByPage(query));
    }

    @PostMapping("/queryWaterLeakHistoryByPage")
    @ApiOperation(value = "分页查询设备漏水的历史记录",response = WaterLeakDeviceHistoryVO.class)
    public Rest<IPage<WaterLeakDeviceHistoryVO>> queryWaterLeakHistoryByPage(@RequestBody @Valid WaterLeakHistoryQuery query){
        return Rest.ok(waterLeakDeviceService.queryWaterLeakHistoryByPage(query));
    }

    @PostMapping("/queryWaterLeakNumCount")
    @ApiOperation(value = "查询设备漏水数量统计",response = WaterLeakDeviceHistoryVO.class)
    public Rest<List<WaterLeakCountVO>> queryWaterLeakNumCount(@RequestBody @Valid WaterLeakHistoryQuery query){
        return Rest.ok(waterLeakDeviceService.queryWaterLeakNumCount(query));
    }

    @PostMapping("/exportWaterLeakHistory")
    @ApiOperation(value = "导出漏水设备历史记录")
    public void exportWaterLeakHistory(@RequestBody @Valid WaterLeakHistoryQuery query, HttpServletResponse response){
        waterLeakDeviceService.exportWaterLeakHistory(query,response);
    }

}
